package search;

import comment.Comment;

/**
 *create by tbj
 */
	//使用迭代二分查找
public class BinarySearch {
	private static int search(int[] a,int target){
		int l=0;
		int r=a.length-1;
		while(l <=r ){
			int mid=l+(r-l)/2;
			if(a[mid]==target){
				return mid;
			}else if(a[mid]<target){
				l=mid+1;
			}else{
				r=mid-1;
			}
		}
		return -1;
	}
	public static void main(String[] args) {
		int[] a=Comment.getOrderedArray(11);
		System.out.println(BinarySearch.search(a, 13));
	}
}
